<?php

/**
 * 日志记录
 * Class LogUtil
 */
class LogUtil
{
    const LOG_FILE = __DIR__ . '/../log/log.log';

    /**
     * @param integer $level [0 continue, 1 exit, 2 complete]
     * @param string $message 消息体
     */
    public static function log(int $level, string $message): void
    {
        $fp = fopen(self::LOG_FILE, 'a+');
        fwrite($fp, $level . '|' . $message . PHP_EOL);
        fclose($fp);
    }

    /**
     * 获取最后一行记录
     * @param int $row
     * @return string
     */
    public static function getLastLog($row)
    {
        if (is_file(self::LOG_FILE)) {
            $fp = file(self::LOG_FILE);
            if (isset($fp[$row])) return $fp[$row];
            else return '';
        } else {
            return '';
        }
    }
}